﻿using System;
using System.Threading.Tasks;
using Dora.Tools.Utility.Const;
using Dora.Tools.Utility.Models;
using Surging.Core.Common;
using Surging.Core.CPlatform.Filters.Implementation;
using Surging.Core.CPlatform.Ioc;
using Surging.Core.CPlatform.Runtime.Server.Implementation.ServiceDiscovery.Attributes;

namespace Dora.Hosts.OAuth.IApplication
{

    [ServiceBundle("api/" + DoraModuleName.OAuthHost + "/{Service}")]
    public interface IOAuthHostService : IServiceKey
    {
        /// <summary>
        /// token的生成，
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="pwd"></param>
        /// <param name="systemKey"></param>
        /// <returns>
        /// token分三段，中间用.隔开，第一段为base64的时间戳，第二段为base64的DtUnionId，第三段为签名结果 
        /// </returns>
        [Service(Date = "2019-02-27", Director = "库尔班大叔", Name = "登录并生成token,dtUnionId为则用username和pwd登录")]
        Task<ResultDto> GenerateTokenCredential(string userName, string pwd,  string systemKey);

        /// <summary>
        /// 小程序登录,并返回token
        /// </summary>
        /// <param name="code"></param>
        /// <param name="avatarUrl"></param>
        /// <param name="nickName"></param>
        /// <param name="gender"></param>
        /// <param name="systemKey"></param>
        /// <returns></returns>
        [Service(Date = "2019-06-22", Director = "TTTan", Name = "登录并生成token,dtUnionId为则用username和pwd登录")]
        Task<ResultDto> WxOpenLogin(string code,  string avatarUrl, string nickName, int gender,int topOrgId, string systemKey);

        /// <summary>
        /// 验证用户是否有api的权限 
        /// </summary>
        /// <param name="authkeyStr"></param>
        /// <returns></returns>
        [Service(Date = "2019-02-27", Director = "库尔班大叔", Name = "验证用户是否有对某个接口的访问，网关用")]
        Task<bool> VerifyPermissions(string authkeyStr,string token);

        [Service(Date = "2019-02-27", Director = "库尔班大叔", Name = "token有效性的验证，网关用")]
        Task<bool> Validate(string token);

        /// <summary>
        /// token换用户
        /// </summary>
        /// <returns></returns>
        [Service(Date = "2019-02-27", Director = "库尔班大叔", Name = "注销token的接口")]
        [Authorization(AuthType = AuthorizationType.JWT)]
        Task DestoryClientAuthentication(string token);

        [Service(Date = "2019-02-27", Director = "库尔班大叔", Name = "token有效性的验证，网关用")]
        Task<string> GetPayload(string token);
        
        Task<DateTime> GetDateTime();
        
        Task<IdentityUserDto> GetUserInfo(string token);
        
        /// <summary>
        /// 供应商通过手机号登录之发送短信验证码
        /// </summary>
        /// <param name="mobile"></param>
        /// <returns></returns>
        [Service(Date = "2019-08-09", Director = "TTTan", Name = "供应商通过手机号登录之发送短信验证码")]
        Task<ResultDto> SendLoginVerifyCode(string mobile, string systemKey);

        /// <summary>
        /// 供应商通过手机号登录之登录
        /// </summary>
        /// <param name="mobile"></param>
        /// <param name="code"></param>
        /// <returns></returns>
        [Service(Date = "2019-08-09", Director = "TTTan", Name = "供应商通过手机号登录之登录")]
        Task<ResultDto> LoginByMobileAndCode(string mobile, string code, string systemKey);
    }
}